const app = getApp();
const https = require('../../utils/https');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    projectList: [],
    house_id: 0,
    loading: false,
    disabled: false,
    house_info: ''
  },
  listTap(e) {
    var check_item_id = e.currentTarget.dataset.check_item_id,
        house_id = this.data.house_id;
    wx.navigateTo({
      url: '/pages/inspection_link/link?check_item_id='+check_item_id+'&house_id='+house_id,
    })
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this,
      is_login_inspector = wx.getStorageSync('is_login_inspector');
    if (!is_login_inspector || is_login_inspector != 1) {
      wx.showToast({
        title: '请先登陆验房师账号',
        icon: 'none',
        duration: 1500
      })
      wx.navigateBack({
        delta: 0,
      })
      return false;
    }
    if (options && options.house_id != '') {
      that.setData({
        house_id: options.house_id
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.getCheckItems();
  },
  /**
   * @xk 获取验房类型
   */
  getCheckItems: function(){
    var that = this,
        house_id = this.data.house_id;
    https.post('getCheckItems',{house_id:house_id},false,'加载中').then(res=>{
      that.setData({
        projectList: res.list,
        order_info: res.order_info,
        house_info: res.house_info
      })
    })
  },
  /**
   * @xk 验收完毕
   */
  checkOver: function(){
    var that = this,
        house_id = this.data.house_id;
    wx.showModal({
      title: '验房确认',
      content: '您确定该房间全部验收完毕？',
      success: function (sm) {
        if (sm.confirm) {
            // 用户点击了确定 可以调用删除方法了
            that.setData({
              loading: true,
              disabled: true,
            })
            https.post('saveCheckHouse',{house_id: house_id},false,'正在提交验房信息').then(res=>{
              wx.navigateBack({
                delta: 0,
              })
            })

          } else if (sm.cancel) {
            console.log('用户点击取消')
          }
        }
      })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    this.onShow();
  },
})